import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

//为了方便测试，此处用vuex做全局数据
const store = new Vuex.Store({
	state: {
		userInfo: {},
		isLogin: false,
		stock:{},
		token: {},
		// systemAppId:"",
		orderType: 1,
		scene: ""
	},
	mutations: {
		SET_ORDER_TYPE(state, orderType) {
			state.orderType = orderType
		},
		SET_ADDRESS(state, address) {
			state.address = address
		},
		SET_REMARK(state, remark) {
			state.remark = remark
		},
		SET_SCENE(state, scene){
			state.scene = scene
		},
		SET_STOCK(state, stock){
			state.stock = stock
			uni.setStorageSync('stock', stock )
		},
		SET_LOGIN(state, data) {
			state.isLogin = data.isLogin
			// state.stock = data.stock
			state.userInfo = data.userInfo
			// state.systemAppId = data.systemAppId
			state.token = data.token
			// uni.setStorageSync('stock', data.stock ) 
			uni.setStorageSync('token', data.token )
			uni.setStorageSync('userInfo', data.userInfo )
			// uni.setStorageSync('systemAppId', data.systemAppId )
		},
		LAY_OUT(state){
			state.isLogin = false
			state.userInfo = {},
			state.token = {},
			uni.removeStorageSync('token')
			uni.removeStorageSync('userInfo')
		}
	}
})

export default store
